<?php

namespace app\admin\controller;

use app\common\controller\Admin;
use think\Request;

class Wallet extends Admin
{
    public function index()
    {
        $get = input('get.');
        //条数
        $limit = $get['limit']?? 10;
        //当前页数
        $curl = $get['page']?? 1;
        $id = $get['battery_order'];
        if(!$id){
            return '没有参数';
        }else{
            $this->assign('id',$id);
        }
        if($this->request->isPost())
        {
            $post = input('post.');
            $where = [];
            $where['user_id'] = $id;
            //开始结束时间
            $where['time'] = $post['time']??'';
            //类型
            $where['class'] = $post['class']??'';
            $wheres =[];
            if($where['time']){
                list($first,$last) = explode('至',$where['time']);
                $wheres[] = ['create_time','>',trim($first)];
                $wheres[] = ['overtime','<',trim($last)];
            }
            foreach ($where as $k=>$v){
                if(strlen($v)>0){
                    if($k !== 'time') $wheres[] = [$k,'=',$v];
                }
            }
            if($wheres){
                $list = model($this->request->controller())->where($wheres)->paginate($limit);
                $page = $list->render();
                $list = $list->toArray()['data'];
                $count = count(model($this->request->controller())->where($wheres)->select()->toArray());
            }else{
                $list = model($this->request->controller())->where('user_id','=',$id)->paginate($limit);
                $page = $list->render();
                $list = $list->toArray()['data'];
                $count = count(model($this->request->controller())->select()->toArray());
            }
        }else{
            $list = model($this->request->controller())->where('user_id','=',$id)->paginate($limit);
            $page = $list->render();
            $list = $list->toArray()['data'];
            $count = count(model($this->request->controller())->select()->toArray());
        }
        $get = input('get.');
        if(isset($get['battery_order'])){
            $this->assign('id',$get['battery_order']);
        }
        $this->assign('list',$list);
        $this->assign('page',$page);
        //总个数
        $this->assign('count',$count);
        //显示条数
        $this->assign('limit',$limit);
        //当前页数
        $this->assign('curl',$curl);
        //页码数
        $groups = ceil($count/$limit);
        $this->assign('groups',$groups);
        return $this->fetch();
    }
}
